<?php
namespace App\Http\Resources\System\Permission\TreeOrg;

use App\Http\Resources\Resource;
use App\Http\Resources\Traits\Attributes;
use App\Http\Resources\Common\TreeResource;
use App\Models\Game\Platform\Org;

class OrgResource extends Resource
{
    use Attributes;

    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
        $orgList = Org::makeAllOrgs($this->resource->pluck('id')->all());

        $this->fillAttributes([
            'orgList' => TreeResource::make($orgList)->toTree($request),
            'orgs' => [
                'ids' => $this->resource->pluck('id')->all()
            ]
        ]);

        return $this->getResponse()->setResponseData($this->getAttributes());
    }
}
